<template>
  <div>

    <el-dialog
      v-if="dialogVisible"
      title="项目验收申请"
      :visible.sync="dialogVisible"
      width="750px"
      :before-close="handleClose">

      <el-form ref="form" :model="form" label-width="150px">

        <el-form-item label="项目名称">
          <div>{{project.project_name}}</div>
        </el-form-item>

        <el-form-item label="项目验收报告">
          <upload ref="upload" :edit-list="form.report" @uploadSuccess="uploadSuccess" @deleteSuccess="deleteSuccess"/>
        </el-form-item>

        <el-form-item label="项目验收材料">
          <el-checkbox v-model="form.check_files_offline">线下提交</el-checkbox>
          <upload ref="upload1" v-if="!form.check_files_offline" :edit-list="form.check_files" :limit="6" @uploadSuccess="uploadSuccess1" @deleteSuccess="deleteSuccess1" />
        </el-form-item>

      </el-form>

      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="confirmClick">确 定</el-button>
        </span>
    </el-dialog>

  </div>
</template>

<script>
    export default {
        name: "projectReportDialog",
        data:function () {
            return{
                dialogVisible:false,
                form:{
                    report:[],
                    check_files:[],
                    check_files_offline:false,
                }
            }
        },
        methods:{
            deleteSuccess() {
                this.form.report = this.$refs.upload.emitFileList()
            },
            uploadSuccess() {
                this.form.report = this.$refs.upload.emitFileList()
            },
            deleteSuccess1() {
                this.form.check_files = this.$refs.upload1.emitFileList()
            },
            uploadSuccess1() {
                this.form.check_files = this.$refs.upload1.emitFileList()
            },
            handleClose:function () {
                this.dialogVisible = false;
            },
            confirmClick:function () {
                if (!this.form.report.length){
                    this.$message.error("请提交验收报告");
                    return
                }
                if (!this.form.check_files_offline && !this.form.check_files.length){
                    this.$message.error("请提交项目验收材料");
                    return
                }

                this.form.report.forEach(item=>{item.model_id = this.project.id;item.model_no = this.project.project_no;item.project_id = this.project.id;item.project_name = this.project.project_name;})
                this.form.check_files.forEach(item=>{item.model_id = this.project.id;item.model_no = this.project.project_no;item.project_id = this.project.id;item.project_name = this.project.project_name;})

                this.dialogVisible = false;
                let data = {...this.form}
                if (data.check_files_offline){
                    data.check_files = []
                }
                data.check_files_offline = Number(data.check_files_offline)
                this.$api.PROJECT_MANAGER_PROJECT_END_CHECK(this.project.id,data).then(res=>{
                    if (res.code == 200){
                        this.$message.success("提交成功")
                        this.$emit("update")
                    }else {
                        this.$message.error(res.msg);
                    }
                })
            },
            showDialog:function (data) {
                this.project = data;
                this.form.report = []
                this.form.check_files = []
                this.form.check_files_offline = false;
                this.dialogVisible = true;

            }
        }
    }
</script>

<style scoped>

</style>
